package com.kgc.sbt.provider;

import com.alibaba.dubbo.config.annotation.Service;
import com.kgc.sbt.api.TradeOrderApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;

import javax.jms.Destination;

/**
 * Created on 2021-06-19.
 * <p>
 * Author: zhukang
 * <p>
 * Description: 提供下单服务
 */
@Service
@Slf4j
public class TradeOrderProvider implements TradeOrderApi {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Override
    public void createTraeOrder(String tradeOrderNo, String prodId, String userId) {
        // 收到下单请求，参数校验，封装实体等，发送消息队列
        log.info("****** 收到生成订单请求，订单号{}, 发送消息队列 ******", tradeOrderNo);

        // 创建消息队列
        Destination destination = new ActiveMQQueue("buy-limit-create-order-queue");

        // 发送消息队列
        jmsMessagingTemplate.convertAndSend(destination, tradeOrderNo);
    }
}
